/**
 * 
 */
package menus.flower;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.geom.Point2D;

import menus.common.AbstractItem;
import menus.common.AbstractMenu;
import fr.lri.swingstates.canvas.CPolyLine;

/**
 * @author insitu
 *
 */
public class FlowerMenuItem extends AbstractItem {

	protected int orientation, kind, rotatingDirection, index;
	
	/**
	 * The approximative width for this mark
	 */
	protected int markWidth = 150;
	
	/**
	 * The approximative height for this mark
	 */
	protected int markHeight = 225;
	
	/**
	 * 
	 * @param menu
	 * @param label
	 * @param index
	 * @param orientation
	 * @param kind
	 * @param rotatingDirection
	 */
	public FlowerMenuItem(AbstractMenu menu, String label, int index, int orientation, int kind, int rotatingDirection, String tag) {
		
		super(menu, label, tag);
		
		this.index = index;
		
		this.orientation = orientation;
		this.kind = kind;
		this.rotatingDirection = rotatingDirection;
		
	}
	
	public FlowerMenuItem(AbstractMenu menu, String label, int index, int orientation, int kind, int rotatingDirection, String tag, int markWidth, int markHeight) {
		
		this(menu, label, index, orientation, kind, rotatingDirection, tag);
		
		this.markWidth = markWidth;
		this.markHeight = markHeight;
		
	}
	
	/**
	 * Generates and fades a clone of the visual elements of this item away, at the specified location
	 * @param where
	 */
	public void ghost(Point2D where, boolean ok, double width, double height) {
		
		ghost(where, createShape(width, height), ok);
		
	}
	
	/**
	 * Generates a mark, without adding it to the canvas or the menu.
	 * Can be used for generating the menu or the ghosts.
	 * 
	 * @return
	 */
	@Override
	public CPolyLine createShape(){
		return createShape(markWidth, markHeight);
	}
	
	public static CPolyLine createShape(int kind, int rotatingDirection, int orientation, double markWidth, double markHeight, String tag){
		
		CPolyLine mark = new CPolyLine(0, 0);
		
		mark.setOutlinePaint(Color.blue)
			.setStroke(new BasicStroke(3))
			.setFilled(false)
			
			.addTag(tag)
			
			.setPickable(false)
			.setDrawable(false);
		
		switch ((kind+1)/2) {
		case 0:
			
			mark.lineTo(markHeight, 0);
			
			break;
			
		case 1:
			
			mark.curveTo(
					.5 * markHeight, 
					0, 
					
					.8 * markHeight, 
					0,//.2 * markWidth * -rotatingDirection, 
					
					markHeight, 
					.6 * markWidth * -rotatingDirection
			);
			
			break;
		
		case 2:
			
			mark.curveTo(
					.8 * markHeight, 
					0, 
					
					.8 * markHeight, 
					.6 * markWidth * -rotatingDirection, 
					
					.5 * markHeight, 
					.6 * markWidth * -rotatingDirection);
			
			break;
	
		case 3:
			
			mark.curveTo(
					1.5 * markHeight, 
					0, 
					
					.4 * markHeight, 
					.8 * markWidth * -rotatingDirection, 
					
					.2 * markHeight, 
					0
			);
			
			break;

		default:
			break;
		}
		
		mark.setReferencePoint(0, (rotatingDirection==-1?0:1));
		
		mark.rotateBy(-orientation * 2 * Math.PI / 8);
		
		return mark;
		
	}
	
	public CPolyLine createShape(double markWidth, double markHeight){
		
		return createShape(kind, rotatingDirection, orientation, markWidth, markHeight, tag);
		
	}

}
